
TOPDIR	:= $(CURDIR)
export	TOPDIR

include $(TOPDIR)/config.mk

# macro definitions for target file

SUBDIRS	= common \
	$(TARGET_DIR)
LDSCRIPT= common/common.lds

# macro definitions for object flags
OBJS= $(TOPDIR)/common/start.o \
	  $(TOPDIR)/common/IGlobalVar.o

# macro definitions for library flags

LIBS = $(TARGET_DIR)/$(APP_NAME).a
LIBS += $(LIB_DIR)/libc.a $(LIB_DIR)/libgcc.a


ALL = $(APP_NAME).exe

all : $(ALL)

$(APP_NAME).exe : $(APP_NAME).bin
	$(APMK) -module $(APP_MODULE) -icon1 $(TARGET_DIR)/ico1.bin -icon2 $(TARGET_DIR)/ico2.bin -name $(APP_NAME) -i $(APP_NAME).bin -o $(APP_NAME).exe

$(APP_NAME).bin : $(APP_NAME).elf
	$(OBJCOPY) -O binary --gap-fill 255 -I elf32-little $(APP_NAME).elf $(APP_NAME).bin

$(APP_NAME).elf : depend subdirs $(OBJS) $(LIBS) $(LDSCRIPT)
	$(LD) -T $(LDSCRIPT) -Map $(APP_NAME).map -N -o $@ $(OBJS) $(LIBS)
#	$(OBJDUMP) -D $(APP_NAME).elf > $(APP_NAME).lst

subdirs:
		@for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir || exit 1 ; done

depend dep:
		for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir .depend ; done

# clean files except source

clean:
	for dir in $(SUBDIRS) ; do $(MAKE) -C $$dir clean ; done
	$(RM) -f $(APP_NAME).elf $(APP_NAME).bin $(APP_NAME).exe $(APP_NAME).map

